package com.uchengwang.ui.base_ui.basefm;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;

import com.flyco.tablayout.SlidingTabLayout;
import com.uchengwang.R;
import com.uchengwang.functions.http.config.BaseConfig;
import com.uchengwang.ui.base_ui.ActivityTitleBar;
import com.uchengwang.ui.cm_ui.cycle.fm.FragmentFollow;
import com.uchengwang.ui.cm_ui.cycle.fm.FragmentJiewu;
import com.uchengwang.ui.cm_ui.cycle.fm.FragmentMusicTalent;
import com.uchengwang.ui.cm_ui.cycle.ui.LoadCycleWebHtmlActivity;
import com.uchengwang.ui.cm_ui.cycle.ui.MsgNoticyActivity;
import com.uchengwang.ui.cm_ui.release.ui.ChooseVideoActivity;
import com.uchengwang.ui.cm_ui.ucity.ui.ReleaseDynamicActivity;
import com.uchengwang.ui.cm_ui.uu.bean.ChooseItemBean;
import com.uchengwang.ui.utils.PopupUtils;
import com.uchengwang.ui.view.MyViewPager;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by U城网 on 2018/2/8.
 * 达人圈首页
 */

public class FragmentTalent extends BaseFragment{
    private View view;

    private String[] clubTitles = {"关注", "音乐", "街舞"};
    private SlidingTabLayout talent_tab;
    private MyViewPager talent_pager;
    private ActivityTitleBar titleBar;
    private ArrayList<Fragment> fragmentList = new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        setLayoutId(R.layout.fm_cycle_layout);
        view = super.onCreateView(inflater, container, savedInstanceState);

        initView();
        return view;
    }

    private void initView() {
        titleBar = view.findViewById(R.id.talent_titleBar);
        talent_tab = view.findViewById(R.id.talent_tab);
        talent_pager = view.findViewById(R.id.talent_pager);

        initData();
    }

    private void initData(){
        titleBar.setTitle("达人圈", R.color.white);
        titleBar.getTitleBar_bg().setBackground(null);

        if (fragmentList.size() >0){
            fragmentList.clear();
        }
        fragmentList.add(new FragmentFollow());
        fragmentList.add(new FragmentMusicTalent());
        fragmentList.add(new FragmentJiewu());

        talent_tab.setViewPagerFm(talent_pager, clubTitles, this, fragmentList);

        initTitleItem();

//        talent_tab.setOnTabSelectListener(new OnTabSelectListener() {
//            @Override
//            public void onTabSelect(int position) {
//                initTitleItem(position);
//            }
//
//            @Override
//            public void onTabReselect(int position) {
//
//            }
//        });
    }

    /**
     * 标题栏的操作键
     * */
    private void initTitleItem(){
        titleBar.setImageRight(R.drawable.fast_release_photo,  new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final List<ChooseItemBean> chooseItemBeans = new ArrayList<>();
                chooseItemBeans.add(new ChooseItemBean("享说", R.drawable.icon_main_speek, 0, R.color.ustudy_no_choose));
                chooseItemBeans.add(new ChooseItemBean("视频", R.drawable.icon_main_video, 0, R.color.ustudy_no_choose));
                chooseItemBeans.add(new ChooseItemBean("文章", R.drawable.icon_main_vote, 0, R.color.ustudy_no_choose));


                PopupUtils.getUtils().rgihtMoreWithIcon(FragmentTalent.this.getContext(), titleBar, chooseItemBeans, R.drawable.shape_item_bg, new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        PopupUtils.getUtils().dismiss();
                        Intent intent = null;
                        switch (chooseItemBeans.get(i).getTitle()){
                            case "享说":
                                intent = new Intent(FragmentTalent.this.getContext(), ReleaseDynamicActivity.class);
                                break;
                            case "视频":
                                intent = new Intent(FragmentTalent.this.getContext(), ChooseVideoActivity.class);
                                break;
                            case "文章":
                                intent = new Intent(FragmentTalent.this.getContext(), LoadCycleWebHtmlActivity.class);
                                intent.putExtra(BaseConfig.IS_FULL, false);
                                intent.putExtra(BaseConfig.IS_HIDE_RIGHT, true);
                                intent.putExtra(BaseConfig.URL, BaseConfig.BaseWebURL + "/article/prepare");
                                break;
                        }
                        if (intent != null){
                            startActivity(intent);
                        }
                    }
                });
            }
        });
        titleBar.setImageLeft(R.drawable.club_release_msg_no, 96, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(FragmentTalent.this.getContext(), MsgNoticyActivity.class));
                titleBar.setLeftMsg(View.GONE, 0);
            }
        });

    }

}
